<template>
	<section id="securityTpwd">
		<HeaDer :Title='titleData'></HeaDer>
		<section class="tpwdWarp">
			<section class="title">
				<h2>设置登录密码</h2>
			</section>

			<section class="formWarp">
				<van-cell-group>
					<van-field v-model="userData.opwd" placeholder="请输入原始密码" :type='isShow.type' :icon="isShow.icon" @click-icon="switchs(1)" />
					<van-field v-model="userData.pw1" placeholder="请输入密码" :type='isShow.otype' :icon="isShow.oicon" @click-icon="switchs(2)" />
					<van-field v-model="userData.pw2" placeholder="请再次输入密码" :type='isShow.ttype' :icon="isShow.ticon" @click-icon="switchs(3)" />
				</van-cell-group>
				<section class="btnWarp" @click="submit">
					<section class="btn">
						提交
					</section>
				</section>

			</section>
		</section>
	</section>
</template>

<script>
	import HeaDer from "../common/header.vue";
	export default {
		data() {
			return {
				titleData: {
					name: '',
					flat: 1
				},
				//控制密码显隐和icon数据
				isShow: {
					icon: 'password-not-view',
					type: 'password',
					oicon: 'password-not-view',
					otype: 'password',
					ticon: 'password-not-view',
					ttype: 'password'
				},
				userData: {
					opwd: '', //原始密码
					pw1: '', //新密码
					pw2: '', //确认新密码
					mobile: sessionStorage.mobile //手机号
				}
			}
		},
		methods: {
			switchs(index) {
				this.$public.switchs(index, this);
			},
			//点击提交执行函数
			submit() {
				var _this = this;
				if(!_this.$public.pwd(_this.userData.opwd)) {
					_this.$toast('原始密码格式有误');
					return false
				} else if(!_this.$public.pwd(_this.userData.pw1) || !_this.$public.pwd(_this.userData.pw2)) {
					_this.$toast('密码格式有误');
					return false
				} else if(_this.userData.pw1 != _this.userData.pw2) {
					_this.$toast('两次输入密码不一致');
					return false
				}
				_this.$public.loading('设置中...',_this);
				_this.$http.post(_this.$host.reset_pwd1, _this.userData).then(function(data) {
					_this.$toast(data.data.msg);
						if(data.data.status == 200){
							_this.$public.go('security',200,_this);
						}else{
							_this.userData.opwd = '';
							_this.userData.pw1 = '';
							_this.userData.pw2 = '';
						}

				}).catch(function() {})
			}
		},
		components: {
			'HeaDer': HeaDer

		},
		created: function() {}
	}
</script>

<style>

</style>